import React from 'react';
import { withRouter } from 'umi';
import { useRequest, defaultFormatResult } from '@/hooks';
import { Spin, Empty } from 'antd';
import TrialCard from '../containers/TrialCard';
import { getAssessRecords } from '../services';

const TrialDetail = ({ location }) => {
    const { query = {} } = location;
    const { employeeCode } = query;
    // 获取试用评估数据
    const { data: infoList, loading } = useRequest(() => getAssessRecords(employeeCode), {
        refreshDeps: [employeeCode],
        ready: !!employeeCode,
        ...defaultFormatResult
    });

    return (
        <div style={{ marginTop: loading ? '50px' : '', minHeight: 150 }}>
            <Spin spinning={loading}>
                {infoList?.length > 0 && (
                    <div>
                        {infoList.map(item => (
                            <TrialCard data={item}></TrialCard>
                        ))}
                    </div>
                )}
                {infoList && infoList.length === 0 && (
                    <div style={{ marginTop: 50 }}>
                        <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
                    </div>
                )}
            </Spin>
        </div>
    );
};

export default withRouter(TrialDetail);
